const { UserModel } = require("./model/userModels/userModel");
const AvatarModel = require("./model/fileModels/avatarModel")
module.exports = {
  register: async (formData) => {
    const data = await UserModel.findOne({ username: formData.username });
    if (!data) {
      return await UserModel.create(formData);
    }
  },
  login: async (loginInfo) => {
    const { username } = loginInfo;
    const data = await UserModel.findOne({ username })
      .populate('avatarId')
      .exec();
    console.log("dao => 登录", data);
    return data;
  },
  getUserInfo: async (userId) => {
    console.log(`获取用户信息：${userId}`)
    const data = await UserModel.findOne({userId})
      .populate('avatarId')
      .exec();
    console.log('获取头像信息', data)
    return data
  }
};
